<template>
  <div class="info">
    <van-nav-bar title="个人资料" left-arrow @click-left="back" />
    <div class="container">
      <ul>
        <li>
          <span>头像</span>
          <van-icon name="arrow" />
          <div class="header">
            <img :src="info.uheader" alt />
          </div>
        </li>
        <li v-tap="{methods:pname}">
          <span>昵称</span>
          <van-icon name="arrow" />
          <span class="name">{{info.uname}}</span>
        </li>
        <li v-tap="{methods:show}">
          <span>生日</span>
          <van-icon name="arrow" />
        </li>
        <li v-tap="{methods:show}">
          <span>性别</span>
          <van-icon name="arrow" />
        </li>
      </ul>
      <van-popup v-model="flag" position="bottom" :style="{ height: '40%' }">
        <van-radio-group v-model="radio">
          <van-cell-group>
            <van-cell title="男" clickable @click="radio = '1'">
              <van-radio slot="right-icon" name="1" />
            </van-cell>
            <van-cell title="女" clickable @click="radio = '2'">
              <van-radio slot="right-icon" name="2" />
            </van-cell>
          </van-cell-group>
        </van-radio-group>
        <van-button class="btn" type="info" v-tap="{methods:update}">确定</van-button>
      </van-popup>
    </div>
  </div>
</template>

<script>
import * as api from "../api/User";
import { Dialog } from "vant";
export default {
  name: "myinfo",
  data() {
    return {
      flag: false,
      info: {},
      radio: ""
    };
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    show() {
      this.flag = !this.flag;
    },
    formatter(type, value) {
      if (type === "year") {
        return `${value}年`;
      } else if (type === "month") {
        return `${value}月`;
      } else if (type === "day") {
        return `${value}日`;
      }
      return value;
    },
    pname() {
      this.$router.push("/updatename");
    },
    update() {
      var usex = "";
      if (this.radio == 1) {
        usex = "男";
      } else if (this.radio == 2) {
        usex = "女";
      }
      api
        .updateUser({
          uheader: this.info.uheader,
          uname: this.info.uname,
          birthday: this.info.birthday,
          usex: usex,
          vip: "1"
        })
        .then(data => {
          console.log(data.data);
          if (data.data.code == "200") {
            Dialog.alert({
              message: "修改成功"
            });
          }
        });
      this.flag = false;
    }
  },
  mounted() {
    api.getOneUser().then(data => {
      this.info = data.data.result[0];
      if(this.info.uheader == 'null' || this.info.uheader == null){
           this.info.uheader = 'http://47.96.143.29/img/default.jpeg';
        }

    });
  }
};
</script>

<style scoped>
.van-ellipsis {
  font-size: 30px;
}
.van-icon {
  color: #333;
}
.container {
  width: 100%;
  padding-top: 10px;
}
.container ul {
  background: #fff;
}
.container ul li {
  height: 120px;
  width: 100%;
  box-sizing: border-box;
  line-height: 120px;
  padding: 0 30px;
  position: relative;
  border-bottom: solid 1px #eee;
}
.container ul li .header {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  float: right;
  margin-right: 20px;
  margin-top: 20px;
}
.container ul li .header img {
  width: 100%;
}
.container ul li span {
  float: left;
  font-size: 28px;
}
.container ul li .name {
  float: right;
  margin-right: 30px;
}

.container ul li .van-icon {
  float: right;
  margin-top: 45px;
  font-size: 28px;
}
/deep/.van-picker__confirm,
/deep/.van-picker__cancel {
  color: #333;
}
.van-popup {
  padding: 50px;
  box-sizing: border-box;
}
.btn {
  float: right;
  margin-top: 10px;
  background: #000;
  border: 0;
}
.van-cell__title {
  text-align: center;
}
</style>